package com.wavefax.minbang.xu.learning.utils;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CsvGenerator {
    public static void main(String[] args){
        Date date = new Date();//时间戳
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String filename = "csv测试文件";
        String path = "D:/wavefax" + "/" +filename +dateFormat.format(date) + ".csv";
        int rowNum = 11000000;//150万生成72M；1100万为580M
        try{
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path)),"utf-8"));
            writer.append("name,age,sex,num,work,weight,height\n");//csv文件第一行
            System.out.println("csv文件生成中...");
            for(int i=0;i<rowNum;i++){
                String temp = i+","+i+","+i+","+i+","+i+","+i+","+i;
                writer.append(temp);
                if(i!=rowNum){
                    writer.append("\n");
                }
                writer.flush();
            }
            writer.close();
            System.out.println("csv文件生成成功，位置:"+path);
        }catch (Exception e){

        }
    }
}
